//
//  SDPhotoPaientCell.m
//  SKinDiary
//
//  Created by pcyang on 16/7/16.
//  Copyright © 2016年 tencent. All rights reserved.
//

#import "SDPhotoPaientCell.h"
#import "SDPhotoInfo.h"
#import "SDPaientInfoItem.h"
#import "SDPaientInfoMgr.h"

#define kTagLeftPadding 10

@interface SDPhotoPaientCell()
@property(nonatomic,strong)UILabel* titleLabel;
@property(nonatomic,strong)UILabel* nameLabel;
@property(nonatomic,strong)UILabel* idLabel;
@property(nonatomic,strong)UILabel* arrowLabel;
@end

@implementation SDPhotoPaientCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 13)];
        _titleLabel.font = [UIFont systemFontOfSize:13];
        _titleLabel.textColor = [UIColor colorWithRGB:0xb4bec8];
        _titleLabel.textAlignment = NSTextAlignmentRight;
        _titleLabel.text = @"患者";
        [self.contentView addSubview:_titleLabel];
        
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 13)];
        _nameLabel.font = [UIFont systemFontOfSize:13];
        _nameLabel.textColor = [UIColor colorWithRGB:0x747f8b];
        [self.contentView addSubview:_nameLabel];
        
        _idLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 13)];
        _idLabel.font = [UIFont systemFontOfSize:13];
        _idLabel.textColor = [UIColor colorWithRGB:0xb4bec8];
        [self.contentView addSubview:_idLabel];
        
        _arrowLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 13)];
        _arrowLabel.font = [UIFont systemFontOfSize:13];
        _arrowLabel.textColor = [UIColor colorWithRGB:0x747f8b];
        _arrowLabel.text = @">";
        [self.contentView addSubview:_arrowLabel];
        
        UIView* bottomLineView = [[UIView alloc] initWithFrame:CGRectMake(kTagLeftPadding, kPhotoPaientCellHeight - 1, kScreenWidth - 2*kTagLeftPadding, 1)];
        [bottomLineView setBackgroundColor:[UIColor colorWithRGB:0xcad6e3]];
        [self.contentView addSubview:bottomLineView];

        
    }
    return self;
}

-(void)setCellData:(SDPaientInfoItem*)paientInfo
{
    if (paientInfo != nil) {
        SDPaientInfoMgr* paientInfoMgr = [SDPaientInfoMgr shareAGDatabaseManager];
        NSArray* itemsArray = [paientInfoMgr select:[SDPaientInfoItem class] tableName:kPaientTableName where:[NSString stringWithFormat:@"pId = %ld",(long)paientInfo.pId]];
        if (CHECK_VALID_ARRAY(itemsArray)) {
            SDPaientInfoItem* paientInfo = [itemsArray objectAtIndex:0];
            _nameLabel.text = paientInfo.name;
            _idLabel.text = [NSString stringWithFormat:@"(ID:%@)",paientInfo.cId];  //显示用cid
        }
    }

    [_titleLabel sizeToFit];
    [_nameLabel sizeToFit];
    [_idLabel sizeToFit];
    [_arrowLabel sizeToFit];
    [self setNeedsLayout];
}

-(void)layoutSubviews
{
    _titleLabel.right = 75;
    _nameLabel.left = _titleLabel.right + 20;
    _idLabel.left = _nameLabel.right + 10;
    _arrowLabel.right = kScreenWidth - 20;
    _titleLabel.centerY = self.centerY;
    _nameLabel.centerY = self.centerY;
    _idLabel.centerY = self.centerY;
    _arrowLabel.centerY = self.centerY;
}
@end
